package demo;

import utils.DBUtils;

import java.sql.*;
import java.util.Scanner;

/**
 * @author tongchen
 * @create 2022-12-27 12:53
 */
public class Select {
    private static ResultSet resultSet;
    private static Connection connection;
    private static PreparedStatement statement;
    public static void main(String[] args) {
        try {
             connection = DBUtils.getConnection();
            Scanner scan=new Scanner(System.in);
            System.out.println("请输入id");
            String names=scan.next();
            //写sql
            String sql="select *from student where name ='"+names+"'";
            //获取执行对象
             statement = connection.prepareStatement(sql);
            //执行sql语句
             resultSet = statement.executeQuery();
            //获取返回结果
            if(resultSet.next()){
                int id=resultSet.getInt(1);
                String sn=resultSet.getString(2);
                String name=resultSet.getString(3);
                String qq_email=resultSet.getString(4);
                int classes_id=resultSet.getInt(5);
                System.out.println(id+","+sn+","+name+","+qq_email+","+classes_id);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        finally {
            DBUtils.closeResources(connection,statement,resultSet);
        }
    }
}
